/**
 * MapTestJava.java
 *
 * @author: ZhuJiahui
 * @date: 2019/3/10 14:06
 */
package six;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.VoidFunction;

import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: ZhuJiahui
 * @version: 1.0
 */
public class MapTestJava {

    public static void main(String[] args) {
        SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("MapTest");
        JavaSparkContext sc = new JavaSparkContext(conf);

        List<String> list = Arrays.asList("张无忌","赵敏","周芷若");
        JavaRDD<String> listRdd = sc.parallelize(list);

//        JavaRDD<String> nameRdd = listRdd.map(new Function<String, String>() {
//            @Override
//            public String call(String v1) throws Exception {
//                return "Hello " + v1;
//            }
//        });
        JavaRDD<String> nameRdd = listRdd.map(name -> {
            return "Hello " + name;
        });

//        nameRdd.foreach(new VoidFunction<String>() {
//            @Override
//            public void call(String s) throws Exception {
//                System.out.println(s);
//            }
//        });
        nameRdd.foreach(name -> System.out.println(name));
    }
}
